package com.zhou.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhou.bpm.domain.vo.HistoryVo;
import com.zhou.bpm.domain.vo.WorkspaceVo;
import com.zhou.bpm.service.IWorkspaceService;
import com.zhou.common.Result;
import com.zhou.common.UserContext;
import com.zhou.test.domain.vo.StatisticVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: zhoujinchuan
 * @Description: TODO（请添加描述）
 * @CreateTime: 2023/10/26 10:22
 */
@RestController
@RequestMapping("approveInfo")
@Api(tags = "审批信息")
public class WorkspaceController {

    @Autowired
    private IWorkspaceService workspaceService;

    @ApiOperation("审批流程历史")
    @GetMapping("approvalProcess")
    public Result<List<HistoryVo>> approvalProcess(Integer instanceId) {
        List<HistoryVo> list = workspaceService.approvalProcess(instanceId);
        return Result.success(list);
    }

    @ApiOperation("我的统计")
    @GetMapping("statistics")
    public Result<StatisticVo> statistic() {
        StatisticVo statisticVo = new StatisticVo();
        Integer userId = UserContext.getUserId();
        //1-我的申请 2-我的待办 3我的已办
        statisticVo.setMyToDoNum((int) workspaceService.pageQuery(0, 1, userId, null, "2").getTotal());
        statisticVo.setMyApprovedNumber((int) workspaceService.pageQuery(0, 1, userId, null, "3").getTotal());
        statisticVo.setMyApplyNum((int) workspaceService.pageQuery(0, 1, userId, null, "1").getTotal());
        return Result.success(statisticVo);
    }

    @ApiOperation("我的流程")
    @GetMapping("pageList")
    public Result<Page<WorkspaceVo>> pageList(@RequestParam(value = "pageNum", defaultValue = "0") Integer pageNum,
                                              @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                              @RequestParam("type") String type) {
        Integer userId = UserContext.getUserId();
        return Result.success(workspaceService.pageQuery(pageNum, pageSize, userId, null, type));
    }


}
